package com.archermind.amosp;

import java.util.ArrayList;

import com.archermind.amosp.AmospOrderAdapter.ViewHolder;

import DataManager.DataManager;
import DataManager.OrderInfo;
import android.app.Activity;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class AmospOrderListActivity extends ListActivity {
    DataManager mDataManager;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_amosp_order_list);
		mDataManager = DataManager.getInstance();
		setListAdapter(new SampleAdapter(mDataManager.getOrderList()));
	}
	
    
	class SampleAdapter extends BaseAdapter {
        private ArrayList<OrderInfo> mItems;

        public SampleAdapter(ArrayList<OrderInfo> items) {
            mItems = items;
        }

        @Override
        public int getCount() {
            return mItems.size();
        }

        @Override
        public Object getItem(int position) {
            return mItems.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
        	
        	ViewHolder holder;
            if (convertView == null) {
                convertView = getLayoutInflater().inflate(R.layout.amosp_order_item,
                        parent, false);
                holder = new ViewHolder();
                holder.name = (TextView)convertView.findViewById(R.id.item_order_name);
                holder.count = (TextView)convertView.findViewById(R.id.item_order_count);
                convertView.setTag(holder);
            }else{
            	holder = (ViewHolder)convertView.getTag();
            }
            OrderInfo info = mItems.get(position);
            holder.name.setText(info.getName());
            String strCount = String.valueOf(info.getCout());
            holder.count.setText(strCount);
            return convertView;
        }
    }
	
    static class ViewHolder {
        TextView name;
        TextView count;
    }
}
